<template>
    <el-form ref="form" label-width="100px" :model="form" :inline="inline">
        <el-form-item v-for="item in formLabel" :key="item.label" :label="item.label">
            <el-input
                v-if="item.type ==='input'"
                :placeholder="'请输入'+ item.label"
                v-model="myForm[item.model]"
                @input="update(myForm[item.model],item.model)"
                :form = "myForm"
                ></el-input>
            <el-switch
                v-if="item.type ==='switch'"
                v-model="myForm[item.model]"
                @change="update(myForm[item.model],item.model)"
                :form = "myForm"
            ></el-switch>
            <el-date-picker
                v-if="item.type === 'date'"
                type="date"
                value-format="yyyy-MM-dd"
                palceholder="请选择入职时间"
                v-model="myForm[item.model]"
                :form = "myForm"
                @change="update(myForm[item.model],item.model)"
            ></el-date-picker>
            <el-select
                v-if="item.type==='select'"
                palceholder="请选择"
                value=" "
                v-model="myForm[item.model]"
                :form = "myForm"
                @change="update(myForm[item.model],item.model)"
            >
            <el-option
            v-for="item in item.opts"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item><slot></slot></el-form-item>
    </el-form>
</template>

<script>
export default {
    // 组件名称
    name: 'commonForm',
    data() {
        return {
        }
    },
    computed:{
        myForm(){
            return this.form
        }
    },
    props: {
        formLabel: Array,
        form: Object,
        inline: Boolean
    },
    methods:{
        update(newForm,name) {
            this.$set(this.myForm,name,newForm) 
            this.$emit("formChanged",newForm,name)
        },
    }
}
</script> 

<style scoped lang='less'>
</style>
